<%- include('head') -%>
</head>
<body>
    <div class="layui-container-fluid">
        <!-- 面包屑导航 -->
        <form class="layui-form" action="">
            <div class="layui-form-item">
              <label class="layui-form-label">用户名</label>
              <div class="layui-input-block">
                <input type="text" name="userName" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label"> 密码</label>
              <div class="layui-input-inline">
                <input type="password" name="pwd" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
              </div>
            </div>
            
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
              </div>
            </div>
          </form>
    </div>
<%- include('footer') -%>
<script>
    layui.use(['form','jquery','layer'],()=>{
            //监听提交
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;
        form.on('submit(formDemo)', function(data){
            // 发请求
            $.ajax({
                url:'/login',
                type:'POST',
                data:{
                    ...data.field
                },
                dataType:"json",
                success:function(res){
                    if(res.code === 0){
                        layer.msg('登录成功', function(){
                            location.href="/admin"   
                        })
                    }else{
                        layer.msg(res.msg)
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>
